//
//  ZQKFeeSettingTableViewCell.m
//  jianzhik
//
//  Created by huami on 2018/8/30.
//  Copyright © 2018年 WKWebView. All rights reserved.
//

#import "ZQKFeeSettingTableViewCell.h"
#import "ZQ_GetCurrentViewNavTool.h"
@implementation ZQKFeeSettingTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)changeBtnClick:(UIButton *)sender {
    UIAlertController * alert = [UIAlertController
                                 alertControllerWithTitle:@"设置矿工费"
                                 message:nil
                                 preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"提交"
                                style:UIAlertActionStyleDestructive
                                handler:^(UIAlertAction * action) {
                                    NSLog(@"提交后%@",alert.textFields.lastObject.text);

                                    [self changeKGF:alert];

                                }];
    
    UIAlertAction* noButton = [UIAlertAction
                               actionWithTitle:@"取消"
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction * action) {
                                   //Handle no, thanks button
                               }];
    
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"请在此输入矿工费数值";
    }];

    [alert addAction:yesButton];
    [alert addAction:noButton];
    [[ZQ_GetCurrentViewNavTool viewControllerSupportView:self] presentViewController:alert animated:YES completion:nil];
}

- (void)setModel:(ZQMoneyModels *)model
{
    _model = model;
    self.bTypeLabel.text = model.Symbol;

    self.kgfLabel.text = [NSString stringWithFormat:@"当前矿工费：%f",model.Fee];
}

- (void)changeKGF:(UIAlertController *)alert
{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"Id"] = self.model.Id;
    parameters[@"Fee"] = alert.textFields.lastObject.text;

    [ZQAFHelper afnetworkRequestWithPostURL:@"/v1/user/updatecoin" parameters:parameters view:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view finishedBlcok:^(NSDictionary *dict) {
        [UIHelper showSuccessMessage:@"修改成功" afterHideHud:2 toView:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view completion:^{
            self.kgfLabel.text =  [NSString stringWithFormat:@"当前矿工费：%@",alert.textFields.lastObject.text];
        }];
    }];
}
@end
